Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation service settings by provided schema ability. #1276

Conversation

wiva-koikoi
Copy link
Contributor

@wiva-koikoi wiva-koikoi commented Mar 3, 2024

📝 Description

Add new setting "$validationSchema" and validation step.
With it (if broker.validator is defined) we can validate service settings object after merged() (means after merging all mixins with own settings) but before created() calls.

🎯 Relevant issues

💎 Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

📜 Example code

import { ValidationSchema } from "fastest-validator";

const $validationSchema: ValidationSchema = {
  $$strict: false,

  batchSize: { integer: true, positive: true, type: "number" },
};


const serviceSchema: ServiceSchema = {
    settings: {
        $validationSchema,

        // throws ValidationError, because batchSize setting expects number.
        batchSize: "10",
    },
};

🏁 Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas

@icebob
Copy link
Member

icebob commented Mar 31, 2024

Nice, but while it doesn't affect the core logic, it can be a nice external middleware (using the serviceCreating hook). So please create a separate repo under your account and publish it as middleware and send us to the awesome-moleculer repo.

@icebob icebob closed this Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants